import javax.sound.sampled.*;
import java.io.*;

/**
 * SoundPlayer
 * Handles sound loading and playback for client.
 * @author James Varvaro
 */
public class SoundPlayer {
    //private AudioInputStream[] pianoNotes = new AudioInputStream[12];
    private String[] pianoClipFileNames = {"piano_glow.wav", "piano_a.wav", "piano_bb.wav", "piano_b.wav",
                                        "piano_c.wav", "piano_cs.wav", "piano_d.wav", "piano_eb.wav",
                                        "piano_e.wav", "piano_f.wav", "piano_fs.wav", "piano_ghigh.wav"};;
    String soundDir = "./sounds/";
    public SoundPlayer() throws Exception {
        // load sound clips
                                        
        /*
        for(int i=0; i < pianoNotes.length; i++) {
            pianoNotes[i] = AudioSystem.getAudioInputStream(new File(soundDir + pianoClipFileNames[i]));
        }
        */
    }
    
    public void playNote(int noteid, String instrumentType, int pitch) throws Exception {
        System.out.println("play" + pitch);
        Clip clip = AudioSystem.getClip();
        if(instrumentType.equals("piano")) {
            if(pitch >= 0 && pitch < pianoClipFileNames.length) {
                AudioInputStream note = AudioSystem.getAudioInputStream(new File(soundDir + pianoClipFileNames[pitch]));
                clip.open(note);
                clip.start();
            }
        }
    }
}
